﻿/**
作者：角色
时间：2009-11-23
功能：实现角色修改
**/
var Obj = new Object();
var id = "";
function ShowMain() {
    id = request("RoleID");
    GetRole();
}

//获取"信息"
function GetRole() {
    var url = encodeURI(SBasePath + '/action/RolesManage/GetRole.aspx?id=' + id);
    var pars = encodeURI('');
    var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sGetRole, onFailure: fGetRole });
}

//获取"信息"成功
function sGetRole(o) {
    Obj = MapAdmin_Roless(o);
    ShowEdit();
}
function fGetRole() {

}

function OutName() {
    if (document.getElementById("RoleName").value == "") {
        $("RoleNamediv").style.display = "";
        return false;
    } else {
        $("RoleNamediv").style.display = "none";
        var url = encodeURI(SBasePath + '/action/RolesManage/RoleExist.aspx');
        var pars = encodeURI("?RoleName=" + document.getElementById("RoleName").value);
        var myAjax = new Ajax.Request(url, { method: 'get', parameters: pars, onComplete: sFormSubmitExist, onFailure: fFormSubmitExist });
    }
}
function sFormSubmitExist(o) {

    var root = o.responseXML.documentElement;

    var OutputFlag = GetXmlData(root, "Value");
    if (OutputFlag == "True") {
        $("RoleNameExist").style.display = "";
        return false;
    }
    else {
        $("RoleNameExist").style.display = "none";
        return true;
    }

}

function fFormSubmitExist() {

}


//提交
function sbmt() {
    if (CheckForm()) {
        var url = encodeURI(SBasePath + '/action/rolesmanage/EditRole.aspx');
        var myAjax = new Ajax.Request(url, { method: 'post', parameters: Form.serialize("formsubmit"), onComplete: sFormSubmit, onFailure: fFormSubmit });
    }
};

//提交成功
var sFormSubmit = function(o) {
    var root = o.responseXML.documentElement;
    var OutputFlag = GetXmlData(root, "Value");

    if (OutputFlag == "true") {
        MsgDlgLocal('修改成功！');
    }

};

//提交失败
var fFormSubmit = function(o) {
};

var CheckForm = function() {

    var fobj = $("formsubmit");

    if (Trim(fobj.RoleName.value) == "") {
        $("RoleNamediv").style.display = "";
        return false;
    }
    else {
        $("RoleNamediv").style.display = "none";
    }
    return true;
};


function ShowEdit() {
    var str = "";
    str += '<form id="formsubmit">';
    str+='<input type="hidden" name="RoleID" value="'+Obj.RoleID+'"/>'
    str += '<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
    str += '<tr>';
    str += '    <td height="30">';
    str += '        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '            <tr>';
    str += '                <td width="15" height="30" class="tab03">';
    str += '                </td>';
    str += '                <td class="tab05">';
    str += '                    <div class="title1" style="padding-top: 2px">';
    str += '                        <img src="../../img/1.gif" height="20" width="19" />修改角色</div>';
    str += '                </td>';
    str += '                <td width="14" class="tab07"></td>';
    str += '            </tr>';
    str += '        </table>';
    str += '    </td>';
    str += '</tr>';
    str += '<tr>';
    str += '    <td>';
    str += '        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '            <tr>';
    str += '                <td width="9" class="tab12"></td>';
    str += '                <td bgcolor="#f3ffe3">';
    str += '                    <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '                        <tr>';
    str += '                            <td class="k_hui">';
    str += '                                <table width="97%" border="0" cellspacing="0" cellpadding="0" align="center">';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            角色名称：';
    str += '                                        </td>';
    str += '                                        <td width="25%">';
    str += '                                            <input type="text" name="RoleName" id="RoleName" class="wbk" value="'+Obj.RoleName+'"  onblur="OutName()" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                            <div alght="right" class="clew" id="RoleNamediv" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />角色名称不能为空！</div>';
    str += '                                            <div alght="right" class="clew" id="RoleNameExist" style="display:none">';
    str += '                                                <img src="../../images/lamp.gif" width="15" height="16" align="absmiddle" />角色名称已存在！</div>';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td height="30" width="12%" style="padding-left: 5px">';
    str += '                                            角色描述：';
    str += '                                        </td>';
    str += '                                        <td widht="25%">';
    str += '                                            <textarea name="RoleDesc" id="RoleDesc" cols="50" rows="11" style="height: 100px; width: 250px; border: solid 1px #cadcb2;">'+Obj.RoleDesc+'</textarea>';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                    <tr height="38">';
    str += '                                        <td colspan="2" style="padding-left: 25px" height="30">';
    str += '                                             <input name="提交" type="button" class="bg_g" style="height: 22px; width: 60px; border: solid 1px #cadcb2;"value="提交" onclick="sbmt()" />';
    str += '                                            &nbsp;&nbsp;<input name="重置" type="reset" class="bg_g" style="height: 22px; width: 60px;border: solid 1px #cadcb2;" value="重置" />';
    str += '                                        </td>';
    str += '                                        <td width="52%" class="zw">';
    str += '                                        </td>';
    str += '                                    </tr>';
    str += '                                </table>';
    str += '                             </td>';
    str += '                        </tr>';
    str += '                    </table>';
    str += '                </td>';
    str += '                <td width="9" class="tab16">';
    str += '                </td>';
    str += '            </tr>';
    str += '        </table>';
    str += '    </td>';
    str += '</tr>';
    str += '<tr>';
    str += '    <td height="29">';
    str += '        <table width="100%" border="0" cellspacing="0" cellpadding="0">';
    str += '            <tr>';
    str += '                <td width="15" height="29" class="tab20">';
    str += '                </td>';
    str += '                <td class="tab21">';
    str += '                    &nbsp;';
    str += '                </td>';
    str += '                <td width="14" class="tab22">';
    str += '                </td>';
    str += '            </tr>';
    str += '        </table>';
    str += '    </td>';
    str += '</tr>';
    str += '</table>';
    str += '</form>';
    $("EditRole").innerHTML = str;
}